<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;

use Think\Controller;

class RedController extends CommonController {
    //楼盘项目
    function index() {
        $User = M('prize_store'); // 实例化User对象
        $keywords = $_REQUEST['keys'];
        if ($keywords) {
            $map['name'] = array('like', '%' . $keywords . '%');
            $map['tel'] = array('eq', $keywords); //多条件
            $map['_logic'] = 'OR';
            $where['_complex'] = $map;
        }
        $p = getpage($User, $where, C('List_Len'));
        $list = $User->where($map)->select();
        $this->assign('list', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display('storelist');
    }

    function storeAdd() {
        $id = $_REQUEST['id'];
        $gc = M('prize_store');
        $where['id'] = $id;
        $data = $gc->where($where)->find();
        //echo $gc->getLastSql();exit;
        $this->assign('data', $data);
        $this->display('storeadd');
    }

    function doStore() {
        $gc = M('prize_store');
        if (false === $data = $gc->create()) {
            $this->error($gc->error());
        }
        $id = $_REQUEST['id'];
        if ($id) {
            $data['utime'] = $this->crtTime();
            $state = $gc->where('id=' . $id)->save($data);
        } else {
            $data['ctime'] = $data['utime'] = $this->crtTime();
            $state = $gc->add($data);
        }
        if ($state) {
            $this->success('数据已保存！', "index");
        } else {
            $this->error('数据未保存！');
        }
    }

    function redlist() {
        $User = M('prize_config'); // 实例化User对象

        $where['sid'] = $_REQUEST['sid'];
        $p = getpage($User, $where, C('List_Len'));

        $list = $User->where($where)->order('id asc')->select();

        $this->assign('list', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display('redlist');
    }

    function redadd() {
        $id = $_REQUEST['id'];
        $gc = M('prize_config');
        $where['id'] = $id;
        $data = $gc->where($where)->find();
        //echo $gc->getLastSql();exit;
        $this->assign('data', $data);
        $this->display('redadd');
    }

    function doAdd() {
        $gc = M('prize_config');
        if (false === $data = $gc->create()) {
            $this->error($gc->error());
        }
        //print_r($data);exit;
        $id = $_REQUEST['id'];
        if ($id) {
            $data['utime'] = $this->crtTime();
            $state = $gc->where('id=' . $id)->save($data);
        } else {
            $data['praisenumber'] = $data['praisetotal'];
            $data['ctime'] = $data['utime'] = $this->crtTime();
            $state = $gc->add($data);
        }
        if ($state) {
            $this->success('数据已保存！', "redlist?sid=" . $data['sid']);
        } else {
            $this->error('数据未保存！');
        }
    }
    //删除红包
    function delered() {
        $id = $_REQUEST['id'];
        $status = $_REQUEST['status'];
        $User = M('prize_config'); // 实例化User对象

        $state = $User->where('id=' . $id)->save(array('status' => $status, 'utime' => $this->crtTime()));
        if ($state) {

            $this->success('数据已保存！', "redlist?sid=" . $_REQUEST['sid']);
        } else {
            $this->error('数据未保存！');
        }
    }
    //查看中奖人员列表
    function seeorder() {
        $m = M('prize_order');
        $where['prizeid'] = $_REQUEST['id'];
        $p = getpage($m, $where, C('List_Len'));
        $data = $m->where($where)->select();//中奖日志
        $this->assign('title', M('prize_store')->where('id=' . $_REQUEST['sid'])->getField('title'));//楼盘名
        $this->assign('praisename', M('prize_config')->where('id=' . $_REQUEST['id'])->getField('praisename'));//奖项名
        $this->assign('data', $data);
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display();
    }

}

?>
